define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/order/index',
                    // add_url: 'order/order/add',
                    // edit_url: 'order/order/edit',
                    del_url: 'order/order/del',
                    // multi_url: 'order/order/multi',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'order_sn', title: __('Order_sn'), operate:false},
                        {field: 'master_order_sn', title: __('Master_order_sn'), visible:false, operate:false},
                        {field: 'user_id_text', title: __('User_id'), operate:false},
                        {field: 'pay_status', title: __('Pay_status'), visible:false, searchList: {"0":__('Pay_status 0'),"1":__('Pay_status 1'),"2":__('Pay_status 2'),"3":__('Pay_status 3'),"4":__('Pay_status 4')}},
                        {field: 'order_status', title: __('Order_status'), visible:false, searchList: {"0":__('Order_status 0'),"1":__('Order_status 1'),"2":__('Order_status 2'),"3":__('Order_status 3'),"4":__('Order_status 4'),"5":__('Order_status 5')}},
                        {field: 'order_status_text', title: __('Order_status'), operate:false},

                        {field: 'pay_status_text', title: __('Pay_status'), operate:false, operate:false},
                        {field: 'goods_id_text', title: __('Goods_id'),width:'150px', operate:false},
                        {field: 'goods_price', title: __('Goods_price'), operate:'BETWEEN', operate:false},
                        {field: 'integral', title: __('Integral'), operate:false},
                        {field: 'type', title: __('Type'), visible:false, searchList: {"0":__('Type 0'),"1":__('Type 1'),"2":__('Type 2')}, operate:false},
                        {field: 'type_text', title: __('Type'), operate:false},
                        {field: 'address_id', title: __('Address_id'),visible:false, operate:false},
                        {field: 'total_amount', title: __('Total_amount'), operate:'BETWEEN', operate:false},
                        {field: 'order_amount', title: __('Order_amount'), operate:'BETWEEN',visible:false, operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate:false},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'transaction_id', title: __('Transaction_id'),visible:false, operate:false},
                        {field: 'deleted', title: __('Deleted'), visible:false, searchList: {"1":__('Deleted 1'),"0":__('Deleted 0')},visible:false, operate:false},
                        {field: 'deleted_text', title: __('Deleted'), operate:false,visible:false, operate:false},
                        {field: 'first_user_id', title: __('First_user_id'),visible:false, operate:false},
                        {field: 'shipping_status', title: __('Shipping_status'), visible:false, searchList: {"0":__('Shipping_status 0'),"1":__('Shipping_status 1')}},
                        {field: 'shipping_status_text', title: __('Shipping_status'), operate:false},
                        {field: 'shipping_code', title: __('Shipping_code'),visible:false, operate:false},
                        {field: 'shipping_name', title: __('Shipping_name'),visible:false, operate:false},
                        {field: 'item_id', title: __('Item_id'),visible:false, operate:false},
                        {field: 'order_prom_type', title: __('Order_prom_type'), visible:false, searchList: {"0":__('Order_prom_type 0'),"1":__('Order_prom_type 1'),"2":__('Order_prom_type 2'),"3":__('Order_prom_type 3'),"4":__('Order_prom_type 4')},visible:false, operate:false},
                        {field: 'order_prom_type_text', title: __('Order_prom_type'), operate:false,visible:false},
                        {field: 'order_prom_id', title: __('Order_prom_id'),visible:false, operate:false},
                        {field: 'user_prom_id', title: __('User_prom_id'),visible:false, operate:false},

                        {field: 'goods_num', title: __('Goods_num'), operate:false, operate:false},
                        //操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮
                        {
                            field: 'operate',
                            width: "120px",
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'addtabs',
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'order/order/detail'
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        },
                    ]
                ],
                //禁用默认搜索
                search: false,
                //启用普通表单搜索
                commonSearch: true,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: true,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});